<?php                                                                                                                                          

class flex_xml{ 
     
    var $root_node = "lua"; 
    var $main_node = "lua"; 
    var $data = array();
    var $xml;
         
    function flex_xml(){ 
    	
    } 
     
    function print_flex_text(){ //netestovane
    	
    	  header("Content-type: text/xml,encoding:\"UTF-8\"");
		  echo "<html><body><pre>".implode("\n",$this->data)."\n</pre></body></html>";                                                                     
	}


    function print_flex_xml(){
    	
    	header("Content-type: text/html,encoding:\"UTF-8\"");
    	$xmlstr = "<".$this->root_node."></".$this->root_node.">";
//    	$xmlstr = "<lua></lua>";
//    	$xmlstr = "";
    	  //Debug string
	  if( !is_array( $this->data )  ){
	    $this->data = array( array('error' => 'No error msg available') );
	  }
    	$xml = new DomDocument('1.0');

	$root = $xml->createElement($this->root_node);
	$root = $xml->appendChild($root);
	
    	foreach( $this->data as $k => $v ) {

    		$txt1 = $xml->createElement($this->main_node);
		$txt1 = $root->appendChild($txt1);
    		
    		foreach( $v as $nodename => $val ) {
        		////$txt2 = $txt1->addChild($nodename, $val );
        		// echo $nodename.'='.$val."<br>";
        	 //Prazdne value neberie, tak davam mimo error msgs:
			// @$txt1->addAttribute( $nodename, $val );
			$txt1->setAttribute( $nodename, $val );
			}
    	}
    	echo $xml->saveXML();
  }//print_flex_xml


    function print_flex_header(){    	
    	header("Content-type: text/html,encoding:\"UTF-8\"");
    	$this->xml = new DomDocument('1.0');
    	$root = $this->xml->createElement($this->main_node);
	$root = $this->xml->appendChild($root);
    	$txt1 = $this->xml->createElement("node");
	$ret = $root->appendChild($txt1);
	$ret->setAttribute( 'label', 'Main' );
	return $ret;
    }

    function add_flex_node($myxml, $data){    	
    }

    

    function print_flex_footer(){
    	echo $this->xml->saveXML();
    }
	
} 

                                                                                                                                               
?>
